
//
//  SEGPictorialManager.m
//  ExcellentHome
//
//  Created by Sam on 16/8/22.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "SEGPictorialManager.h"
@implementation SEGPictorialManager

//新版的画报详情数据整理
//1. 获取点赞总人数
#pragma mark - 画报详情－获取点赞总人数
- (void)requestPictorialDetailWithPictorialId:(NSString*)pictorialId Finished:(SEGRequestCallBack)finished
{
    NSDictionary* params = @{
                             @"pictorialId" : pictorialId,
                             @"code" : @(SEGEnumAdvertismentIdType_PGC_LIST),
                             @"userId" : kAccountUserID
                             };
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/cms-api/pictorial/detail.json",nil];

    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        if ([result valueForKey:@"data"] && [[result valueForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
            NSDictionary* dicData = [result valueForKey:@"data"];
            
            if (!([[dicData allKeys] containsObject:@"pictorial"] && [[dicData objectForKey:@"pictorial"] isKindOfClass:[NSDictionary class]])) {
                finished(NO, @"", @"数据返回为空！"); //数据返回正常，但是数据为空
                return;
            }
            
            self.dataSourcePictorialDetail = [SEGPictorialDetailModel initWithDictionary:[dicData valueForKey:@"pictorial"]];
            
            finished(YES, codeType, errorMessage);
        }
        finished(isSuccessed, codeType, errorMessage);
    }];
}

//2.拉取点赞人的头像
#pragma mark - 根据业务对象ID获取对应操作人员的列表－拉取点赞人的头像
- (void)requestPictorialFindPraiseListById:(NSString*)objId
                                   ObjType:(NSString*)objType
                                      Type:(NSString*)type
                                  Finished:(SEGRequestCallBack)finished
{
    NSDictionary* params = @{
                             @"objId" : objId,
                             @"objType" : objType, //1画报 2 问题 3 评论 4 问题答案
                             @"type" : type //1 为点赞 2为浏览 3为收藏
                             };
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/cms-api/pictorial/findPraiseListById.json",nil];

    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        if ([result valueForKey:@"data"] && [[result valueForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
            NSDictionary* dicData = [result valueForKey:@"data"];
            
            if (![dicData objectForKey:@"praiseList"]) {
                
                finished(NO, @"", @"数据返回为空！"); //数据返回正常，但是数据为空
                return;
            }
            
            NSArray* pictorialList = [dicData valueForKey:@"praiseList"];
            
            NSMutableArray* arrM = [NSMutableArray arrayWithCapacity:pictorialList.count];
            
            for (NSDictionary* dic in pictorialList) {
                
                SEGPictorialDetailPraiseListModel* _model = [SEGPictorialDetailPraiseListModel initWithDictionary:dic];
                
                [arrM addObject:_model];
            }
            
            self.dataSourcePraiseList = arrM;
            
            finished(YES, codeType, @"");
        }
        finished(isSuccessed, codeType, errorMessage);
    }];

}
//3.拉取活动广告
#pragma mark - 广告信息列表 画报用来统计用户总评论-拉取活动广告
- (void)requestpictoriaAdvlistBypositionType:(SEGAdvlistType)positionType
                                    Finished:(SEGRequestCallBack)finished
{
    NSDictionary* params = @{
                             @"positionType" : @(positionType)
                             };
    
    __block NSInteger _positionType = positionType;
    [[SEGAdvlistManager sharedManager] segRequestAdvlistWithPositionType:positionType completed:^(BOOL isSuccessed, id  _Nonnull result, NSString * _Nonnull codeType, NSString * _Nonnull errorMessage) {
        
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        if ([result valueForKey:@"data"] && [[result valueForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
            NSArray* dicData = [result valueForKey:@"data"];
            
            NSMutableArray* arrM = [NSMutableArray arrayWithCapacity:dicData.count];
            NSMutableArray* arrM1 = [NSMutableArray array];
            
            for (NSDictionary* dic in dicData) {
                
                SEGPictorialDetailAdListModel* _model = [SEGPictorialDetailAdListModel initWithDictionary:dic];
                
                if ([_model.position isEqualToString:[NSString stringWithFormat:@"%zd", _positionType]]) {
                    [arrM addObject:_model];
                }
                
                if ([_model.position isEqualToString:@"0"]) {
                    [arrM1 addObject:_model];
                }
            }
            
            /// DataSourceAdList 广告数据源
            self.DataSourceAdList = arrM;
            /// DataSourceAdList_Jump 记录首页弹出广告
            self.DataSourceAdList_Jump = arrM1;
            
            finished(YES, codeType, errorMessage);
        }
        finished(isSuccessed, codeType, errorMessage);
    }];
}

//3.小编推荐
#pragma mark - 画报列表－小编推荐
- (void)requestpictoriaListByType:(NSString*)type ActIndex:(NSString*)actIndex PageNo:(NSInteger)pageNo PageSize:(NSInteger)pageSize QuizTypeId:(NSString*)quizTypeId IsRecommend:(NSString*)isRecommend Finished:(SEGRequestCallBack)finished
{
    SEGProfileModel* Account = [SEGProfileManager sharedManager].profile;
    NSDictionary* params = @{
                             @"type" : type,
                             @"actIndex" : actIndex,
                             @"pageNo" : @(pageNo),
                             @"pageSize" : @(pageSize),
                             @"quizTypeId" : quizTypeId,
                             @"isRecommend" : isRecommend,
                             @"userId" : kAccountUserID,
                             @"provinceId" : Account.provinceId,
                             @"cityId" : Account.cityId,
                             @"regionId" : Account.regionId,
                             @"communityId" : kAccountCommunityID
                             };
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/cms-api/pictorial/list.json",nil];
    
    [[SEGPictoriallistManager sharedManager] requestPictoriallistWithParameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        if ([result valueForKey:@"data"] && [[result valueForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
            NSDictionary* dicData = [result valueForKey:@"data"];
            
            if (![dicData objectForKey:@"pictorialList"]) {
                
                finished(NO, @"", @"数据返回为空！"); //数据返回正常，但是数据为空
                return;
            }
            
            NSArray* pictorialList = [dicData valueForKey:@"pictorialList"];
            
            NSMutableArray* arrM = [NSMutableArray arrayWithCapacity:pictorialList.count];
            
            for (NSDictionary* dic in pictorialList) {
                
                SEGPictorialModel* _model = [SEGPictorialModel initWithDictionary:dic];
                
                [arrM addObject:_model];
            }
            
            self.dataSourcePictorial = arrM;
            finished(YES, codeType, errorMessage);
        }
        finished(isSuccessed, codeType, errorMessage);
    }];
}

#pragma mark - 画报列表－新小编推荐
- (void)requestPgclListByIdBytype:(NSString*)type pictorialId:(NSString*)pictorialId Finished:(SEGRequestCallBack)finished
{
    SEGProfileModel* Account = [SEGProfileManager sharedManager].profile;
    NSDictionary* params = @{
                             @"type" : type,
                             @"pictorialId" : pictorialId,
                             @"provinceId" : Account.provinceId,
                             @"cityId" : Account.cityId,
                             @"regionId" : Account.region,
                             @"communityId" : kAccountCommunityID
                             };
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/cms-api/pictorial/getPgclListById.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        if ([result valueForKey:@"data"] && [[result valueForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
            NSDictionary* dicData = [result valueForKey:@"data"];
            
            NSArray* pictorialList = [dicData valueForKey:@"pictorialList"];
            
            if (pictorialList && pictorialList.count <= 0) {
                finished(NO, codeType, @"数据返回为空！"); //数据返回正常，但是数据为空
                return;
            }
            
            NSMutableArray* arrM = [NSMutableArray array];
            [pictorialList enumerateObjectsUsingBlock:^(NSDictionary*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                SEGPictorialModel* _model = [SEGPictorialModel initWithDictionary:obj];
                [arrM addObject:_model];
                
                if (idx == 2) {
                    *stop = YES;
                }
            }];
            
            self.seg_PgclList = arrM;
            finished(YES, codeType, errorMessage);
        }
        finished(isSuccessed, codeType, errorMessage);
    }];
    
}

- (void)doLogic_PictoriaDetail
{
    
    NSMutableArray<SEGPictorialDoLogicModel*>* arrM_logic = [NSMutableArray array];
    
    //统计用户总总浏览量
    if ([self.dataSourcePictorialDetail.praiseTotal integerValue] > 0) {
        SEGPictorialDoLogicModel* model = [[SEGPictorialDoLogicModel alloc] init];
        model.cellType = SEGPictorialDoLogicModelCellType_PraiseAll;
        model.isShowLineView = NO;
        model.sortIndex = @1;
        model.pictorialDesc = [NSString stringWithFormat:@"共有 %@ 人点赞", [self.dataSourcePictorialDetail.praiseTotal stringValue]];
        [arrM_logic addObject:model];
    }
    
    //统计用户的头像
    if (self.dataSourcePraiseList.count > 0) {
        SEGPictorialDoLogicModel* model = [[SEGPictorialDoLogicModel alloc] init];
        model.cellType = SEGPictorialDoLogicModelCellType_HEADERCOUNT;
        model.isShowLineView = NO;
        model.praiseListCount = self.dataSourcePraiseList;
        model.sortIndex = @2;
        
        NSMutableArray* arrM = [NSMutableArray array];
        for (int i = 0; i < ((self.dataSourcePraiseList.count > 5) ? 5 : self.dataSourcePraiseList.count); i++) {
            [arrM addObject:self.dataSourcePraiseList[i].ico];
        }
        
        model.picCount = arrM;
        [arrM_logic addObject:model];
    }
    
    //统计广告
    if (self.DataSourceAdList.count > 0) {
        SEGPictorialDoLogicModel* model = [[SEGPictorialDoLogicModel alloc] init];
        model.cellType = SEGPictorialDoLogicModelCellType_ADLIST;
        model.isShowLineView = YES;
        model.AdListCount = self.DataSourceAdList;
        model.sortIndex = @3;
        [arrM_logic addObject:model];
    }
    
    //分割线
    if (self.dataSourcePraiseList.count > 0 || self.DataSourceAdList.count > 0) {
        SEGPictorialDoLogicModel* model = [[SEGPictorialDoLogicModel alloc] init];
        model.cellType = SEGPictorialDoLogicModelCellType_LINE;
        model.isShowLineView = NO;
        model.sortIndex = @4;
        [arrM_logic addObject:model];
    }
    
    //统计小编推荐
    if (self.seg_PgclList.count > 0) {
        
        SEGPictorialDoLogicModel* model_H = [[SEGPictorialDoLogicModel alloc] init];
        model_H.cellType = SEGPictorialDoLogicModelCellType_LIST_HEAD;
        model_H.pictorialDesc = @"小编推荐";
        model_H.isShowLineView = NO;
        model_H.sortIndex = @5;
        [arrM_logic addObject:model_H];
        
        SEGPictorialDoLogicModel* model = [[SEGPictorialDoLogicModel alloc] init];
        model.cellType = SEGPictorialDoLogicModelCellType_LIST;
        model.isShowLineView = YES;
        model.listCount = self.seg_PgclList;
        model.sortIndex = @6;
        [arrM_logic addObject:model];
    }
    
    //分割线
    if (self.seg_PgclList.count > 0) {
        SEGPictorialDoLogicModel* model = [[SEGPictorialDoLogicModel alloc] init];
        model.cellType = SEGPictorialDoLogicModelCellType_LINE;
        model.isShowLineView = NO;
        model.sortIndex = @7;
        [arrM_logic addObject:model];
    }
    
    //8. 热门评论
    if (self.seg_CommentList.hotList.count > 0) {
        SEGPictorialDoLogicModel* model_hotList = [[SEGPictorialDoLogicModel alloc] init];
        model_hotList.cellType = SEGPictorialDoLogicModelCellType_HOTLIST;
        model_hotList.hotList = self.seg_CommentList.hotList;
        model_hotList.isShowLineView = NO;
        model_hotList.sortIndex = @8;
        [arrM_logic addObject:model_hotList];
    }
    
    //8. 最新评论
    //if (self.seg_CommentList.commentList.count > 0) {
    SEGPictorialDoLogicModel* model_CommentList = [[SEGPictorialDoLogicModel alloc] init];
    model_CommentList.cellType = SEGPictorialDoLogicModelCellType_COMMENTLIST;
    model_CommentList.commentList = self.seg_CommentList.commentList;
    model_CommentList.isShowLineView = NO;
    model_CommentList.sortIndex = @9;
    model_CommentList.isShowPic = self.seg_CommentList.commentList.count > 0 ? NO : YES;
    [arrM_logic addObject:model_CommentList];
    
    [arrM_logic sortedArrayUsingComparator:^NSComparisonResult(SEGPictorialDoLogicModel* obj1, SEGPictorialDoLogicModel* obj2) {
        NSComparisonResult result = [obj1.sortIndex compare:obj2.sortIndex];
        return result == NSOrderedAscending; // 降序:NSOrderedAscending====升序:NSOrderedDescending
    }];
    
    self.seg_segpictorialdologicmodel = arrM_logic;
}

#pragma mark - 生活画报
- (void)requestPictorialFinished:(SEGRequestCallBack)finished
{
    
    [self requestpictoriaListByType:@"1" ActIndex:@"" PageNo:1 PageSize:10000 QuizTypeId:@"" IsRecommend:@"" Finished:^(BOOL isSuccessed, NSString* codeType, NSString* errorMessage) {
        
        [self dataChange:self.dataSourcePictorial];
        
        finished(isSuccessed, codeType, errorMessage);
    }];
}
#pragma mark - 画报首页
- (void)requestPictorialWithquizTypeId:(NSString*)quizTypeId Finished:(SEGRequestCallBack)finished
{
    [self requestpictoriaListByType:@"1" ActIndex:@"" PageNo:1 PageSize:10000 QuizTypeId:quizTypeId IsRecommend:@"" Finished:finished];
}

////  通过服务器给的原始数据，进行分类（饮食、其他、家居、亲子）
- (void)dataChange:(NSArray<SEGPictorialModel*>*)data
{
    
    //1. 先获取组数：[来判断
    NSMutableArray<SEGPictorialShowModel*>* title = [NSMutableArray array]; //title 的数量就是组的数量
    for (SEGPictorialModel* tmp in data) {
        BOOL hasValue = NO;
        for (SEGPictorialShowModel* _model in title) {
            if ([_model.sectionName isEqualToString:tmp.quizTypeTitle]) {
                hasValue = YES;
            }
        }
        if (!hasValue) {
            SEGPictorialShowModel* _model = [[SEGPictorialShowModel alloc] init];
            _model.sectionName = tmp.quizTypeTitle;
            [title addObject:_model];
        }
    }
    
    for (int i = 0; i < title.count; i++) {
        
        SEGPictorialShowModel* _model = title[i];
        
        NSMutableArray* arrItem = [NSMutableArray array];
        
        for (SEGPictorialModel* tmp in data) {
            if ([_model.sectionName isEqualToString:tmp.quizTypeTitle]) {
                [arrItem addObject:tmp];
            }
        }
        
        _model.rows = arrItem;
        
        title[i] = _model;
    }
    
    self.dataSourceShowPic = title;
}

///  点击“换”按钮 进行内容变换
- (void)exchangeContent
{
    //把每一行形成一个圆行浏览
    NSInteger index = 3;
    
    for (int i = 0; i < self.dataSourceShowPic.count; i++) {
        
        NSMutableArray<SEGPictorialModel*>* arr = [NSMutableArray arrayWithArray:self.dataSourceShowPic[i].rows];
        
        if (arr.count <= index) {
            continue;
        }
        NSRange range = NSMakeRange(0, index);
        //取
        NSArray* arrGet = [arr subarrayWithRange:range];
        //删
        [arr removeObjectsInRange:range];
        //加到尾部
        
        for (SEGPictorialModel* _model in arrGet) {
            [arr insertObject:_model atIndex:arr.count];
        }
        
        self.dataSourceShowPic[i].rows = arr;
    }
}

#pragma mark - 问题类型详情
- (void)requestQuizTypeDetailWithQuizTypeId:(NSString*)quizTypeId Finished:(SEGRequestCallBack)finished
{
    NSDictionary* params = @{
                             @"quizTypeId" : quizTypeId
                             };
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/cms-api/quiz/quizTypeDetail.json",nil];

    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        if ([result valueForKey:@"data"] && [[result valueForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
            NSDictionary* dicData = [result valueForKey:@"data"];
            
            if (![dicData objectForKey:@"quizTypeDetail"]) {
                
                finished(NO, @"", @"数据返回为空！"); //数据返回正常，但是数据为空
                return;
            }
            
            self.dataSourceQuizTypeDetail = [QuizTypeDetailmodel initWithDictionary:[dicData valueForKey:@"quizTypeDetail"]];
            
            finished(YES, codeType, errorMessage);
        }
        finished(isSuccessed, codeType, errorMessage);
    }];
}

#pragma mark - 根据业务ID和业务类型分页获取评论列表
- (void)requestPictorialcommentListByObjID:(NSString*)objId ObjType:(NSString*)objType pageNo:(NSInteger)pageNo pageSize:(NSInteger)pageSize Finished:(SEGRequestCallBack)finished
{
    NSDictionary* params = @{
                             @"objId" : objId,
                             @"objType" : objType,
                             @"pageNo" : @(pageNo),
                             @"pageSize" : @(pageSize),
                             @"userId" : kAccountUserID
                             };
    
    __block NSInteger _page = pageNo;
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kCMS_api,@"/comment/commentListByType.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        if ([result valueForKey:@"data"] && [[result valueForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
            NSDictionary* dicData = [result valueForKey:@"data"];
            
            //新的评论接口
            if (_page == 1) {
                self.seg_CommentList.hotList = @[];
                self.seg_CommentList.commentList = @[];
            }
            
            SEGCommentListModel* arrNew_model = [SEGCommentListModel initWithDictionary:dicData];
            
            if (arrNew_model.hotList.count <= 0 && arrNew_model.commentList.count <= 0) {
                finished(NO, @"-1", @"没有更多的评论！");
                return;
            }
            
            [self doLogicWith:arrNew_model];
            
            NSMutableArray* arrOld_hot = [NSMutableArray arrayWithArray:self.seg_CommentList.hotList];
            NSMutableArray* arrOld_comment = [NSMutableArray arrayWithArray:self.seg_CommentList.commentList];
            
            [arrOld_hot addObjectsFromArray:arrNew_model.hotList];
            [arrOld_comment addObjectsFromArray:arrNew_model.commentList];
            
            self.seg_CommentList.hotList = arrOld_hot;
            self.seg_CommentList.commentList = arrOld_comment;
            
            //============================
            
            if (_page == 1) {
                self.dataSourceCommentList = @[];
            }
            
            NSArray* pictorialList = [dicData valueForKey:@"commentList"];
            
            NSMutableArray* arrM = [NSMutableArray arrayWithCapacity:pictorialList.count];
            
            NSString* userIds = @"";
            for (NSDictionary* dic in pictorialList) {
                
                SEGPictorialDetailCommentListModel* _model = [SEGPictorialDetailCommentListModel initWithDictionary:dic];
                _model.commentContent1 = [_model.commentContent copy];
                if (_model.byReviewNick.length > 0) {
                    _model.commentContent = [NSString stringWithFormat:@"回复 %@：%@", _model.byReviewNick, _model.commentContent];
                }
                
                [arrM addObject:_model];
                
                userIds = [userIds stringByAppendingString:[NSString stringWithFormat:@",%@",_model.userId]];
            }
            
            NSMutableArray* arrOld = [NSMutableArray arrayWithArray:self.dataSourceCommentList];
            [arrOld addObjectsFromArray:arrM];
            
            self.dataSourceCommentList = arrOld;
            
            if ([userIds length] > 0) {
                userIds = [userIds substringFromIndex:1];
            }
            
            finished(YES, codeType, errorMessage);
        }
        finished(isSuccessed, codeType, errorMessage);
    }];

}

//对盖楼式评论的数据整理，楼主放到楼层最后一个
- (void)doLogicWith:(SEGCommentListModel*)data
{
    
    [data.hotList enumerateObjectsUsingBlock:^(SEGPictorialHotListModel* _Nonnull obj, NSUInteger idx, BOOL* _Nonnull stop) {
        
        [obj.floorComments enumerateObjectsUsingBlock:^(SEGFloorCommentsModel* _Nonnull obj, NSUInteger idx, BOOL* _Nonnull stop) {
            obj.floor = idx + 1;
        }];
        
        NSMutableArray<SEGFloorCommentsModel*>* hotList_Floor = [NSMutableArray arrayWithArray:obj.floorComments];
        
        SEGFloorCommentsModel* last = [SEGFloorCommentsModel initWithDictionary:[obj yy_modelToJSONObject]];
        last.floor = obj.floorComments.count + 1;
        last.hasSelected = YES;
        last.floorUserId = obj.userId;
        [hotList_Floor addObject:last];
        obj.floorComments = hotList_Floor;
    }];
    
    [data.commentList enumerateObjectsUsingBlock:^(SEGPictorialCommentListModel* _Nonnull obj, NSUInteger idx, BOOL* _Nonnull stop) {
        
        [obj.floorComments enumerateObjectsUsingBlock:^(SEGFloorCommentsModel* _Nonnull obj, NSUInteger idx, BOOL* _Nonnull stop) {
            obj.floor = idx + 1;
        }];
        
        NSMutableArray<SEGFloorCommentsModel*>* hotList_Floor = [NSMutableArray arrayWithArray:obj.floorComments];
        
        SEGFloorCommentsModel* last = [SEGFloorCommentsModel initWithDictionary:[obj yy_modelToJSONObject]];
        last.floor = obj.floorComments.count + 1;
        last.hasSelected = YES;
        last.floorUserId = obj.userId;
        
        [hotList_Floor addObject:last];
        
        obj.floorComments = hotList_Floor;
    }];
}

- (void)doLogicWithModel:(SEGPictorialHotListModel*)obj
{
    [obj.floorComments enumerateObjectsUsingBlock:^(SEGFloorCommentsModel* _Nonnull obj, NSUInteger idx, BOOL* _Nonnull stop) {
        obj.floor = idx + 1;
    }];
    
    NSMutableArray<SEGFloorCommentsModel*>* hotList_Floor = [NSMutableArray arrayWithArray:obj.floorComments];
    
    SEGFloorCommentsModel* last = [SEGFloorCommentsModel initWithDictionary:[obj yy_modelToJSONObject]];
    last.floor = obj.floorComments.count + 1;
    last.hasSelected = YES;
    
    [hotList_Floor addObject:last];
    
    obj.floorComments = hotList_Floor;
}
#pragma mark - 新增评论
- (void)requestpictoriaCommentSaveByobjId:(NSString*)objId
                                  objType:(NSString*)objType
                           commentContent:(NSString*)commentContent
                                   userId:(NSString*)userId
                                  creator:(NSString*)creator
                               byReviewId:(NSString*)byReviewId
                          sourceCommentId:(NSString*)sourceCommentId
                             byReviewNick:(NSString*)byReviewNick
                           byReviewUserId:(NSString*)byReviewUserId
                            communityName:(NSString*)communityName
                              communityId:(NSString*)communityId
                            objSendUserId:(NSString*)objSendUserId
                          objPicUrlForMsg:(NSString*)objPicUrlForMsg
                           objTitleForMsg:(NSString*)objTitleForMsg
                              parentObjId:(NSString*)parentObjId
                                pramsType:(NSInteger)pramsType
                            parentObjType:(NSInteger)parentObjType
                                 Finished:(SEGRequestCallBack)finished
{
    NSDictionary* params = @{};
    if (pramsType == 1001) {
        params = @{
                   @"objId" : objId,
                   @"objType" : objType,
                   @"commentContent" : commentContent,
                   @"userId" : userId,
                   @"creator" : creator,
                   @"byReviewId" : byReviewId,
                   @"sourceCommentId" : sourceCommentId,
                   @"byReviewNick" : byReviewNick,
                   @"byReviewUserId" : byReviewUserId,
                   @"communityName" : communityName,
                   @"communityId" : communityId,
                   @"objSendUserId" : objSendUserId,
                   @"objPicUrlForMsg" : objPicUrlForMsg,
                   @"objTitleForMsg" : objTitleForMsg,
                   @"parentObjId" : parentObjId,
                   @"parentObjType" : @(parentObjType)
                   };
    }
    else {
        params = @{
                   @"objId" : objId,
                   @"objType" : objType,
                   @"commentContent" : commentContent,
                   @"userId" : userId,
                   @"creator" : creator,
                   @"byReviewId" : byReviewId,
                   @"sourceCommentId" : sourceCommentId,
                   @"byReviewNick" : byReviewNick,
                   @"byReviewUserId" : byReviewUserId,
                   @"communityName" : communityName,
                   @"communityId" : communityId,
                   @"objSendUserId" : objSendUserId,
                   @"objPicUrlForMsg" : objPicUrlForMsg,
                   @"objTitleForMsg" : objTitleForMsg,
                   @"parentObjId" : parentObjId,
                   @"parentObjType" : @(parentObjType)
                   };
    }
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kCMS_api,@"/comment/save.json",nil];

    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        finished(isSuccessed, codeType, errorMessage);
    }];

}

#pragma mark - 画报详情底部数据
- (void)showPicDown
{
    NSMutableArray* arrM = [NSMutableArray array];
    
    //1. 统计广告
    for (int i = 0; i < self.DataSourceAdList.count; i++) {
        SEGPictorialDetailShowDownModel* _model = [[SEGPictorialDetailShowDownModel alloc] init];
        _model.showType = SEGPictorialDetailShowDownModeltYPE_HASAD;
        _model.isLastOne = NO;
        _model.index = i;
        [arrM addObject:_model];
    }
    //2. 统计是否有点赞
    if (self.dataSourcePraiseList.count > 0) {
        
        SEGPictorialDetailShowDownModel* _model = [[SEGPictorialDetailShowDownModel alloc] init];
        _model.showType = SEGPictorialDetailShowDownModeltYPE_HASPRAISE;
        _model.isLastOne = NO;
        [arrM addObject:_model];
        
        //3. 统计点赞
        SEGPictorialDetailShowDownModel* _model1 = [[SEGPictorialDetailShowDownModel alloc] init];
        _model1.showType = SEGPictorialDetailShowDownModeltYPE_PRAISE;
        _model1.isLastOne = NO;
        [arrM addObject:_model1];
    }
    //4. 统计是否有小编推荐
    if (self.dataSourcePictorial.count > 0) {
        SEGPictorialDetailShowDownModel* _model = [[SEGPictorialDetailShowDownModel alloc] init];
        _model.showType = SEGPictorialDetailShowDownModeltYPE_HASPICTORAL;
        _model.isLastOne = NO;
        [arrM addObject:_model];
    }
    //5. 统计小编推荐
    for (int i = 0; i < self.dataSourcePictorial.count; i++) {
        SEGPictorialDetailShowDownModel* _model = [[SEGPictorialDetailShowDownModel alloc] init];
        _model.showType = SEGPictorialDetailShowDownModeltYPE_PICTORAL;
        _model.index = i;
        _model.isLastOne = NO;
        if (i == self.dataSourcePictorial.count - 1) {
            _model.isLastOne = YES;
        }
        
        [arrM addObject:_model];
    }
    //6. 统计是否有评论
    if (self.dataSourceCommentList.count > 0) {
        SEGPictorialDetailShowDownModel* _model = [[SEGPictorialDetailShowDownModel alloc] init];
        _model.showType = SEGPictorialDetailShowDownModeltYPE_HASCOMMENT;
        _model.isLastOne = NO;
        [arrM addObject:_model];
    }
    //7. 统计评论
    for (int i = 0; i < self.dataSourceCommentList.count; i++) {
        SEGPictorialDetailShowDownModel* _model = [[SEGPictorialDetailShowDownModel alloc] init];
        _model.showType = SEGPictorialDetailShowDownModeltYPE_COMMENT;
        _model.index = i;
        _model.isLastOne = NO;
        [arrM addObject:_model];
    }
    
    self.dataSourceDown = arrM;
}

#pragma mark - getter
- (NSArray<SEGPictorialModel*>*)dataSourcePictorial
{
    
    if (!_dataSourcePictorial) {
        
        _dataSourcePictorial = [NSArray array];
    }
    
    return _dataSourcePictorial;
}

- (NSArray<SEGPictorialShowModel*>*)dataSourceShowPic
{
    
    if (!_dataSourceShowPic) {
        
        _dataSourceShowPic = [NSArray array];
    }
    
    return _dataSourceShowPic;
}

- (QuizTypeDetailmodel*)dataSourceQuizTypeDetail
{
    
    if (!_dataSourceQuizTypeDetail) {
        
        _dataSourceQuizTypeDetail = [[QuizTypeDetailmodel alloc] init];
    }
    
    return _dataSourceQuizTypeDetail;
}

- (SEGPictorialDetailModel*)dataSourcePictorialDetail
{
    
    if (!_dataSourcePictorialDetail) {
        
        _dataSourcePictorialDetail = [[SEGPictorialDetailModel alloc] init];
    }
    
    return _dataSourcePictorialDetail;
}

- (NSArray<SEGPictorialDetailPraiseListModel*>*)dataSourcePraiseList
{
    
    if (!_dataSourcePraiseList) {
        
        _dataSourcePraiseList = [NSArray array];
    }
    
    return _dataSourcePraiseList;
}

- (NSArray<SEGPictorialDetailCommentListModel*>*)dataSourceCommentList
{
    
    if (!_dataSourceCommentList) {
        
        _dataSourceCommentList = [NSArray array];
    }
    
    return _dataSourceCommentList;
}

- (NSArray<SEGPictorialDetailAdListModel*>*)DataSourceAdList
{
    if (!_DataSourceAdList) {
        
        _DataSourceAdList = [NSArray array];
    }
    
    return _DataSourceAdList;
}

- (NSArray<SEGPictorialDetailAdListModel*>*)DataSourceAdList_Jump
{
    if (!_DataSourceAdList_Jump) {
        
        _DataSourceAdList_Jump = [NSArray array];
    }
    
    return _DataSourceAdList_Jump;
}

- (NSArray<SEGPictorialDetailShowDownModel*>*)dataSourceDown
{
    if (!_dataSourceDown) {
        
        _dataSourceDown = [NSArray array];
    }
    
    return _dataSourceDown;
}

- (NSArray<SEGPictorialDoLogicModel*>*)seg_segpictorialdologicmodel
{
    if (!_seg_segpictorialdologicmodel) {
        _seg_segpictorialdologicmodel = [NSArray array];
    }
    return _seg_segpictorialdologicmodel;
}

- (SEGCommentListModel*)seg_CommentList
{
    if (!_seg_CommentList) {
        _seg_CommentList = [[SEGCommentListModel alloc] init];
    }
    return _seg_CommentList;
}

- (NSArray<SEGPictorialModel*>*)seg_PgclList
{
    if (!_seg_PgclList) {
        _seg_PgclList = [NSArray array];
    }
    return _seg_PgclList;
}
@end

